package com.itany.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Author：汤小洋
 * Date：2022-11-07 14:28
 * Description：<描述>
 */
@WebServlet("/session")
public class SesssionServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();

        System.out.println(session);
        System.out.println(session.getId());

        session.setMaxInactiveInterval(600); // 10分钟


        session.setAttribute("hobby","movie");

        System.out.println(session.getAttribute("hobby"));

        session.removeAttribute("hobby");


        /**
         * 退出登陆
         */
        session.invalidate();

    }
}
